<template>
  <div>
    <div style="padding:10px 0; width: 50%;">
      <!-- <a-player
        :music="songList"
        :showlrc="3"
        :narrow="false"
        theme="#b7daff"
        mode="circulation"
        v-if="flag"
        listmaxheight="200px"
        ref="player"
        fixed
      ></a-player> -->
      <aplayer  v-if="flag" :audio="songList"  :lrcType="3" :customAudioType="customAudioType" />
    </div>
  </div>
</template>

<script>
import axios from "axios";

import qs from "qs";
export default {
  components: {
    //别忘了引入组件

  },
  data() {
    return {
      flag: false,
      musicList: [],
      songList: [],
      currentMusic:{},
        audio: [
        {
          name: '东西（Cover：林俊呈）',
          artist: '纳豆',
          url: 'https://cdn.moefe.org/music/mp3/thing.mp3',
          cover: 'https://p1.music.126.net/5zs7IvmLv7KahY3BFzUmrg==/109951163635241613.jpg?param=300y300', // prettier-ignore
          lrc: 'https://cdn.moefe.org/music/lrc/thing.lrc',
        },
        {
          name: '响喜乱舞（Cover：MARiA）',
          artist: '泠鸢yousa',
          url: 'https://cdn.moefe.org/music/mp3/kyoukiranbu.mp3',
          cover: 'https://p1.music.126.net/AUGVPQ_rVrngDH9ocQrn3Q==/109951163613037822.jpg?param=300y300', // prettier-ignore
          lrc: 'https://cdn.moefe.org/music/lrc/kyoukiranbu.lrc',
        },
        {
          name: '啵唧',
          artist: 'Hanser',
          url: 'https://cdn.moefe.org/music/mp3/kiss.mp3',
          cover: 'https://p1.music.126.net/K0-IPcIQ9QFvA0jXTBqoWQ==/109951163636756693.jpg?param=300y300', // prettier-ignore
          lrc: 'https://cdn.moefe.org/music/lrc/kiss.lrc',
        },
      ],
    };
  },
  async mounted() {
    //异步加载，先加载出player再使用
    this.init();
    // let aplayer = this.$refs.player.control;
    // aplayer.play();
  },
  methods: {
  async init() {
      var param = {
        TransCode: "020117",
        OpenId: "7cwa.com",
        Body: ""
      };
      this.$req.getEx('Expand/MusicApi/GetMusicList',param).then(res=>{
       this.musicList=res.Body;
//        author: "Ice Paper"
// id: 1349292048
// lrc: "https://api.hibai.cn/music/Music/Music?id=1349292048&type=lrc"
// pic: "https://api.hibai.cn/music/Music/Music?id=1349292048&type=pic"
// time: 186
// title: "心如止水"
// url: "https://api.hibai.cn/music/Music/Music?id=1349292048&type=url"
        this.currentMusic=this.musicList[0];
        this.musicList.forEach(el=>{
          this.songList.push({
            name:el.title,
            artist:el.author,
            url:el.url,
            cover:el.pic,
            lrc:el.lrc,
          })
        })
        // for(let i=0;i<=this.musicList.length;i++){
        //     let obj={};
        //     //url=>歌曲地址 title=>头部 author=>歌手 pic=>写真图片 lrc=>歌词
        //     //其中url必须有，其他的都是非必须
        //     try {
        //          obj.name = this.musicList[i].title;
        //         obj.artist = this.musicList[i].author;
        //         obj.url = this.musicList[i].url;
        //         obj.cover = this.musicList[i].pic;
        //         obj.lrc = this.musicList[i].lrc;
        //     } catch (error) {
        //     }
        //     //把数据一个个push到songList数组中，在a-player标签中使用 :music="songList" 就OK了
        //     this.songList.push(obj);
        // }
        //   console.log(this.songList)
        //因为是异步请求，所以一开始播放器中是没有歌曲的，所有给了个v-if不然会插件默认会先生成播放器，导致报错(这个很重要)
        this.flag = true;
      })
    }
  }
};
</script>

<style scoped>
</style>
